<template>
    <div class="app-container">
        <div class="search-container">
            <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
                <el-form-item label="住院号" prop="clinicNo">
                    <el-input v-model="queryParams.hospitalNo" clearable placeholder="请输入住院号"
                              @keyup.enter="handleQuery"/>
                </el-form-item>
                <el-form-item label="姓名" prop="name">
                    <el-input v-model="queryParams.name" clearable placeholder="请输入姓名" @keyup.enter="handleQuery"/>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="queryParams.phone" clearable placeholder="请输入联系电话"
                              @keyup.enter="handleQuery"/>
                </el-form-item>
                <el-form-item label="身份证号" prop="idNo">
                    <el-input v-model="queryParams.idNo" clearable placeholder="请输入身份证号"
                              @keyup.enter="handleQuery"/>
                </el-form-item>
                <div class="mr20" style="float: right">
                    <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
                </div>
            </el-form>
        </div>
        <el-table v-adaptive="500" :border="true" :data="patVisitPatientList" :header-cell-style="$headerCellStyle" :stripe="true"
                  highlight-current-row>
            <el-table-column :align="'center'" label="住院号" prop="hospitalNo" width="120"/>
            <el-table-column :align="'center'" label="姓名" prop="name" width="120"/>
            <el-table-column :align="'center'" label="费别" prop="chargeType" width="90">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['medical_insurance_type']" :value="scope.row.chargeType"/>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="性别" prop="sex" width="70">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['sys_user_sex']" :value="scope.row.sex"/>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="年龄" prop="age" width="157">
                <template #default="scope">
                    {{ scope.row.age }} 岁
                    {{ scope.row.ageMonth }} 月
                    {{ scope.row.ageDay }} 天
                    {{ scope.row.ageHours }} 时
                    {{ scope.row.ageMinutes }} 分
                </template>
            </el-table-column>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="所在科室" prop="deptStayedName"
                             width="120"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="联系电话" prop="phone" width="120"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="身份证号" prop="idNo" width="170"/>
            <el-table-column :align="'center'" label="出生日期" prop="birthdayDate" width="100">
                <template #default="scope">
                    <span>{{ $parseTime(scope.row.birthdayDate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="住址" prop="address" width="240"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="监护人姓名" prop="guardianName"
                             width="120"/>
            <el-table-column :align="'center'" :show-overflow-tooltip="true" label="监护人电话" prop="guardianPhone"
                             width="120"/>
            <el-table-column :align="'center'" class-name="small-padding fixed-width" fixed="right" label="操作"
                             width="110">
                <template #default="scope">
                    <el-button type="success" @click="introduce(scope.row)">
                        <template #icon>
                            <i-ep-edit/>
                        </template>
                        引用
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum"
                    :total="total" @pagination="getList"/>
    </div>
</template>
<script lang="ts">
export default {
    name: "ClinicMaster"
}
</script>

<script lang="ts" setup>
import {selectPagePatVisit} from "@/api/hospitalization/patVisit.ts";
import {useDictStoreHook} from "@/store/modules/dict";

const dictStore = useDictStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData('sys_user_sex', 'medical_insurance_type'))
const {proxy} = getCurrentInstance() as any;
const emits = defineEmits(["introduce"])
const queryParamsRef = ref()
const patVisitPatientList = ref([]);

const showSearch = ref(true);
const total = ref(0);

const props = defineProps({
    orgId: String,
    name: String,
    settledIndicator: {
        type: String,
        default: 'N'
    },
    // 出院时间是否为空 0是 1否
    isDischargeTime: {
        type: String,
        default: '0'
    }
})
const queryParams = ref<any>({
    pageNum: 1,
    pageSize: 10,
    visitDate: "",
    clinicNo: "",
    name: props.name,
    idNo: "",
    orgId: props.orgId
});

/** 查询住院未结算记录列表 */
function getList() {
    queryParams.value.settledIndicator = props.settledIndicator;
    queryParams.value.isDischargeTime = props.isDischargeTime;
    selectPagePatVisit(queryParams.value).then((response: any) => {
        patVisitPatientList.value = response.rows;
        total.value = response.total;
    });
}


/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParamsRef.value.resetFields()
    handleQuery();
}

function getParentList(obj: any) {
    queryParams.value.name = obj.name
    queryParams.value.chargeFlag = obj.chargeFlag
    getList()
}

/** 引入患者信息 */
function introduce(row) {
    emits("introduce", row)
}

defineExpose({
    getList,
    getParentList
})
</script>
